package com.numbfish.bean_factory.ex_02_config_properties;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;

public class Main {
    public static void main(String[] args) {
        DefaultListableBeanFactory beanRegistry = new DefaultListableBeanFactory();
        BeanFactory container = (BeanFactory)bindViaPropertiesFile(beanRegistry);
        FXNewsProvider newsProvider = (FXNewsProvider)container.getBean("djNewsProvider");
        newsProvider.getAndPersistNews();
    }


    public static BeanFactory bindViaPropertiesFile(BeanDefinitionRegistry registry)
    {
        PropertiesBeanDefinitionReader reader =
                new PropertiesBeanDefinitionReader(registry);
        reader.loadBeanDefinitions("classpath:ex_02/binding-config.properties");
        return (BeanFactory)registry;
    }
}
